#
# create a new document with lat and lng attribute and with img.jpg attached
#

require "rubygems"
require "JSON"
require "net/http"
 
sample = {
  :lat => 62.2,
  :lng => 25.3
}


url = "/butterfly/test" #+ Time.now.tv_sec.to_s
p url
http = Net::HTTP.new("localhost", 5984);
http.start {|http| 
  put = Net::HTTP::Put.new(url, initheader = {'Content-Type' => 'text/json'})
  put.body = sample.to_json
  resp = http.request(put)
  rev = JSON.parse(resp.body)["rev"]
  url = url + '/img.jpg?rev='+rev
  puts "created document, uploading attachment to " + url
  put = Net::HTTP::Put.new(url, initheader = {'Content-Type' => 'image/jpg'})
  put.body = open("img.jpg", "rb") {|io| io.read }
  puts  http.request(put)
}  






